<?php

/**
 * This is the model class for table "tbl_tdoctecnicadados".
 *
 * The followings are the available columns in table 'tbl_tdoctecnicadados':
 * @property integer $id
 * @property string $DocTecnica
 * @property string $DCampo01
 * @property string $DCampo02
 * @property string $DCampo03
 * @property string $DCampo04
 * @property string $DCampo05
 * @property string $DCampo06
 * @property string $DCampo07
 * @property string $DCampo08
 * @property string $DCampo09
 * @property string $DCampo10
 * @property integer $Emprestado
 * @property integer $idProj
 * @property integer $idTipo
 */
class Tdoctecnicadados extends CActiveRecord
{
        public $sDocTecnica;

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_tdoctecnicadados';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			//array('idTipo', 'required'),
			array('Emprestado, idProj, idTipo', 'numerical', 'integerOnly'=>true),
			array('DocTecnica', 'length', 'max'=>20),
			array('DCampo01', 'length', 'max'=>50),
			array('DCampo02, DCampo03, DCampo04, DCampo05, DCampo06, DCampo07, DCampo08, DCampo09', 'length', 'max'=>250),
			array('DCampo10', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, DocTecnica, DCampo01, DCampo02, DCampo03, DCampo04, DCampo05, DCampo06, DCampo07, DCampo08, DCampo09, DCampo10, Emprestado, idProj, idTipo', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
        public function getLabel()
        {
            $criteria = new CDbCriteria();
            $sDocTecnica = Yii::app()->session['tipodoctecnica'];
            //$sDocTecnica = Yii::app()->getRequest()->getQuery('sdoctecnica');
            $criteria->compare('DocTecnica',$sDocTecnica);
            $post=Tipodoctec::model()->find($criteria); // $params não é necessario
            return $post;
        } 
        public function LabelText($key)
        {
            $options = $this->getLabel();
            return $options[$key];
        }
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'DocTecnica' => 'Doc Tecnica',
			'DCampo01' => $this->LabelText('Campo01'),
			'DCampo02' => $this->LabelText('Campo02'),
			'DCampo03' => $this->LabelText('Campo03'),
			'DCampo04' => $this->LabelText('Campo04'),
			'DCampo05' => $this->LabelText('Campo05'),
			'DCampo06' => $this->LabelText('Campo06'),
			'DCampo07' => $this->LabelText('Campo07'),
			'DCampo08' => $this->LabelText('Campo08'),
			'DCampo09' => $this->LabelText('Campo09'),
			'DCampo10' => $this->LabelText('Campo10'),
			'Emprestado' => 'Emprestado',
			'idProj' => 'Id Proj',
			'idTipo' => 'Id Tipo',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.
                $sDocTecnica = Yii::app()->session['tipodoctecnica'];
            
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		//$criteria->compare('DocTecnica',$this->DocTecnica,true);
                $criteria->compare('DocTecnica',$sDocTecnica);
		$criteria->compare('DCampo01',$this->DCampo01,true);
		$criteria->compare('DCampo02',$this->DCampo02,true);
		$criteria->compare('DCampo03',$this->DCampo03,true);
		$criteria->compare('DCampo04',$this->DCampo04,true);
		$criteria->compare('DCampo05',$this->DCampo05,true);
		$criteria->compare('DCampo06',$this->DCampo06,true);
		$criteria->compare('DCampo07',$this->DCampo07,true);
		$criteria->compare('DCampo08',$this->DCampo08,true);
		$criteria->compare('DCampo09',$this->DCampo09,true);
		$criteria->compare('DCampo10',$this->DCampo10,true);
		$criteria->compare('Emprestado',$this->Emprestado);
		$criteria->compare('idProj',$this->idProj);
		$criteria->compare('idTipo',$this->idTipo);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
     


	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Tdoctecnicadados the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
